## Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /etc/portage/bashrc$
# Originally written by Ned Ludd (solar_at_gentoo.org)
# modifications by Ryan McIntosh (thebigslide_at_gmail.com)
# V1.0_rc1
# - /etc/portage/bashrc

loopize()
{
	local file=$1
	local var
	
# Bail if file does not exist or is not readable.
	[[ -r ${ROOT}/etc/portage/package.$file ]] || return 0
	
	while read -a target; do
		unset var
		if [ "${target}" = "${CATEGORY}" -o "${target}" = "${CATEGORY}/${PN}" ]; then
			unset `echo $file | /usr/bin/tr a-z A-Z`
# Skip the package part of the line
			target[0]=""
			for i in "${target[@]}"; do
				case "$i" in
					GLOBALCFLAGS) var="$var $GLOBALCFLAGS" ;;
					GLOBALCXXFLAGS) var="$var $GLOBALCXXFLAGS" ;;
					GLOBALLDFLAGS) var="$var $GLOBALLDFLAGS" ;;
					GLOBALFEATURES) var="$var $GLOBALFEATURES" ;;
					*) var="$var $i"
				esac
			done
			export `echo $file | /usr/bin/tr a-z A-Z`="`echo $var`"
		fi
	done < ${ROOT}/etc/portage/package.$file
}

if [ "$0" = "/usr/lib/portage/bin/ebuild.sh" -o "$0" = "/usr/lib/portage/bin/ebuild-daemon.sh" ]; then
	export GLOBALCFLAGS=$CFLAGS
	export GLOBALCXXFLAGS=$CXXFLAGS
	export GLOBALLDFLAGS=$LDFLAGS
	export GLOBALFEATURES=$FEATURES
	loopize "cflags"
	loopize "cxxflags"
	loopize "ldflags"
	loopize "features"
	unset GLOBALCFLAGS
	unset GLOBALCXXFLAG
	unset GLOBALLDFLAGS
	unset GLOBALFEATURES
else
	echo "This bashrc does not know anything about $0"
fi

